﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Windows;
using System.Data.SqlClient;

namespace INTROSE
{
    public partial class MenuProductionStaff : Form
    {
        SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Database = Introse; Integrated Security = True");
        private string name, position;
        public MenuProductionStaff(string name, string position)
        {
            InitializeComponent();
            this.name = name;
            this.position = position;

            var currentCulture = Thread.CurrentThread.CurrentCulture;
            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-us");
                string LongDateString = DateTime.Now.ToLongDateString();
                lblDate.Text = LongDateString.ToString();
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = currentCulture;
            }
        }

        private void MenuProductionStaff_Load(object sender, EventArgs e)
        {
            lblName.Text=(this.name);
            tmrRefresh.Start();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
            Login login = new Login();
            login.Show();
        }

        private void btnViewTrans_Click(object sender, EventArgs e)
        {
            this.Close();
            View_Transactions_Tabbed viewtrans = new View_Transactions_Tabbed(name, position);
            viewtrans.Show();
        }

        private void btnEditUser_Click(object sender, EventArgs e)
        {
            this.Close();
            Edit_User editname = new Edit_User(name, position, name);
            editname.Show();
        }

        private void btnViewUser_Click(object sender, EventArgs e)
        {
            this.Close();
            View_User viewname = new View_User(name, position, name);
            viewname.Show();
        }

        private void btnDeleteUser_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you want to delete your account?", "Deleting", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                con.Open();
                SqlCommand command = new SqlCommand("Delete from users where userName = '"+name+"'", con);
                command.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("Account successfully deleted!");
                this.Close();
                Login login = new Login();
                login.Show();
            }
        }

        private void tmrRefresh_Tick(object sender, EventArgs e)
        {
            lblTime.Text = DateTime.Now.ToLongTimeString();
        }
    }
}
